<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>苏豫强的作业</title>
    <script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.6.0/jquery.js"></script>
</head>
<style>
    div {
        width: 20px;
        height: 20px;
        border: 1px solid red;
        border-radius: 50%;
        text-align: center;
        margin: 5px;
        float: left;
    }

    .box {
        background: green;
    }
</style>

<body>
    <button id='bt'>开始</button>
    <div class="box">1</div>
    <div>2</div>
    <div>3</div>
    <div>4</div>
    <div>5</div>
    <div>6</div>
    <div>7</div>
    <div>8</div>
    <div>9</div>
    <div>10</div>
    <div>11</div>
    <div>12</div>
    <div>13</div>
    <div>14</div>
    <div>15</div>
    <div>16</div>
    <div>17</div>
    <div>18</div>
    <div>19</div>
    <div>20</div>
    <script>
        var flag = true
        var n = 0
        $('#bt').click(function () {
            if (flag == false) {
                return
            }
            setInterval(function () {
                if (n > 19) {n = 0}
                $(`div:eq(${n})`).css('background', 'green')
                $(`div:eq(${n-1})`).css('background', 'white')
                n++;
                flag = false
            }, 100)
        })
       
    </script>










</body>

</html>